package powell.nflpredictionproject.display;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.*;

/**
 *
 * @author Joshua Powell
 */
public class MainPanel extends JFrame
{

    private UserPanel user = new UserPanel();
    private static int answer = 0;
    private JMenuBar bar = new JMenuBar();
    private JMenu menu = new JMenu("Choose A Year Here");
    private JRadioButton twoOTwelve = new JRadioButton("2012");
    private JRadioButton twoOThirteen = new JRadioButton("2013");
    private ButtonGroup group = new ButtonGroup();
    
    
    public MainPanel()
    {
        answer = 0;
        
        group.add(twoOTwelve);
        group.add(twoOThirteen);

        twoOTwelve.addActionListener(new ButtonListener());
        twoOThirteen.addActionListener(new ButtonListener());

        menu.add(twoOTwelve);

        menu.add(twoOThirteen);

        bar.setBackground(Color.WHITE);
        
        bar.setForeground(Color.BLACK);
        
        bar.add(menu);

        this.add(bar);

        setJMenuBar(bar);

        this.setTitle("NFL Prediction Application");

        this.setLocationRelativeTo(null);

        this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);

        user.getCalculate().addActionListener(new CalculateListener());

        this.setLayout(new GridLayout(2, 1));

        this.add(user, BorderLayout.CENTER);
        this.add(user.ButtonPanel(), BorderLayout.SOUTH);

        this.pack();

        this.setVisible(true);
    }

    private void closeMe()
    {
        this.setVisible(false);
        this.dispose();
    }
    
    public static int getAnswer()
    {
        return answer;
    }

    private class ButtonListener implements ActionListener
    {

        @Override
        public void actionPerformed(ActionEvent e)
        {
            if (twoOTwelve == e.getSource())
            {
               answer = 0; 
            }
            
            if (twoOThirteen == e.getSource())
            {
                answer = 1;
            }
        }
    }

    private class CalculateListener implements ActionListener
    {

        @Override
        public void actionPerformed(ActionEvent e)
        {
            closeMe();
        }
    }
}
